#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>

using namespace std;

void computeTransitiveClosure(vector<vector<int>>& graph, int n) 
{
    vector<vector<int>> transitiveClosure(graph);

    for (int k = 0; k < n; ++k) 
    {
        for (int i = 0; i < n; ++i) 
        {
            for (int j = 0; j < n; ++j) 
            {
                transitiveClosure[i][j] = transitiveClosure[i][j] || (transitiveClosure[i][k] && transitiveClosure[k][j]);
            }
        }
    }

    for (int i = 0; i < n; ++i) 
    {
        for (int j = 0; j < n; ++j) 
        {
            cout << transitiveClosure[i][j] << " ";
        }
        cout << endl;
    }
}

int main() 
{
    int n;
    cin >> n;

    vector<vector<int>> graph(n, vector<int>(n));
    for (int i = 0; i < n; ++i) 
    {
        for (int j = 0; j < n; ++j) 
        {
            cin >> graph[i][j];
        }
    }

    computeTransitiveClosure(graph, n);

    return 0;
}

